<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.ty.mapper.${src}.${entity}Mapper">
	<resultMap id="RM" type="com.ty.model.${src}.${entity}">
		<#if priKey??>
		<id column="${priKey.column}" property="${priKey.property}" jdbcType="${priKey.jdbcType}" />
		<#else>
		<#list priKeys as p>
		<id column="${p.column}" property="${p.property}" jdbcType="${p.jdbcType}" />
		</#list>
		</#if>
		<#list notPriList as c>
		<result column="${c.column}" property="${c.property}" jdbcType="${c.jdbcType}" />
		</#list>
	</resultMap>
	
	<sql id="columns">
		<#list colList as c>${c.column}<#if c_index != colList?size-1>, </#if></#list>
	</sql>
	
	<insert id="save" parameterType="com.ty.model.${src}.${entity}" >
		insert into ${table} (
			<#list colList as c>${c.column}<#if c_index != colList?size-1>, </#if></#list>
		) values (
			<#list colList as c>#${r'{'}${c.property},jdbcType=${c.jdbcType}${r'}'}<#if c_index != colList?size-1>, </#if></#list>
		)
	</insert>
	
	<insert id="saveByEntity" parameterType="com.ty.model.${src}.${entity}" >
		insert into ${table}
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<#list colList as c>
			<if test="${c.property} != null">
				${c.column},
			</if>
			</#list>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<#list colList as c>
			<if test="${c.property} != null">
				#${r'{'}${c.property},jdbcType=${c.jdbcType}${r'}'},
			</if>
			</#list>
		</trim>
	</insert>
	
	<delete id="deleteById" parameterType="<#if priKey??>${priKey.javaType2}<#else>java.util.List</#if>" >
		delete from ${table} where <#if priKey??>${priKey.column} = #${r'{'}${priKey.property},jdbcType=${priKey.jdbcType}${r'}'}<#else><#list priKeys as p>${p.column} = #${r'{'}arg${p_index},jdbcType=${p.jdbcType}${r'}'}<#if p_index != (priKeys?size - 1)> and </#if></#list></#if>
	</delete>
	
	<delete id="delete" >
		delete from ${table} 
		where 1=1
		<include refid="Fragement.and"/>
	</delete>
	
	<update id="update" parameterType="com.ty.model.${src}.${entity}" >
		update ${table}
		set 
			<#list notPriList as c>
			${c.column} = #${r'{'}${c.property},jdbcType=${c.jdbcType}${r'}'}<#if c_index != notPriList?size-1>, </#if>
			</#list>
		where <#if priKey??>${priKey.column} = #${r'{'}${priKey.property},jdbcType=${priKey.jdbcType}${r'}'}<#else><#list priKeys as p>${p.column} = #${r'{'}${p.property},jdbcType=${p.jdbcType}${r'}'}<#if p_index != (priKeys?size - 1)> and </#if></#list></#if>
	</update>
	
	<update id="updateByEntity" parameterType="com.ty.model.${src}.${entity}" >
		update ${table}
		<set>
			<#list notPriList as c>
			<if test="${c.property} != null">
				${c.column} = #${r'{'}${c.property},jdbcType=${c.jdbcType}${r'}'},
			</if>
			</#list>
		</set>
		where <#if priKey??>${priKey.column} = #${r'{'}${priKey.property},jdbcType=${priKey.jdbcType}${r'}'}<#else><#list priKeys as p>${p.column} = #${r'{'}${p.property},jdbcType=${p.jdbcType}${r'}'}<#if p_index != (priKeys?size - 1)> and </#if></#list></#if>
	</update>
	
	<select id="getById" resultMap="RM" parameterType="<#if priKey??>${priKey.javaType2}<#else>java.util.List</#if>">
		select <include refid="columns" />
		from ${table} where <#if priKey??>${priKey.column} = #${r'{'}${priKey.property},jdbcType=${priKey.jdbcType}${r'}'}<#else><#list priKeys as p>${p.column} = #${r'{'}arg${p_index},jdbcType=${p.jdbcType}${r'}'}<#if p_index != (priKeys?size - 1)> and </#if></#list></#if>
	</select>
	
	<select id="findAll" resultMap="RM">
		select <include refid="columns"/>
		from ${table} where 1 = 1
		<include refid="Fragement.and"/>
		<include refid="Fragement.order"/>
		<include refid="Fragement.limit"/>
	</select>
	
	<select id="getCount" resultType="int">
		select count(*) from ${table} where 1 = 1
		<include refid="Fragement.and"/>
	</select>
	
</mapper>